package com.zy.common.core.domain.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.zy.common.annotation.Dict;
import com.zy.common.annotation.Excel;
import com.zy.common.annotation.Excel.ColumnType;
import com.zy.common.annotation.Excel.Type;
import com.zy.common.annotation.Excels;
import com.zy.common.core.domain.BaseEntity;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;
import java.util.List;

/**
 * 用户对象 sys_user
 *
 * @author ruoyi
 */
@Data
@NoArgsConstructor
public class SysUser extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** 用户ID */
    private Long userId;

    /** 部门ID */
    @Excel(name = "部门编号", type = Type.IMPORT)
    private Long deptId;

    /** 用户账号 */
    @Excel(name = "登录名称")
    private String userName;

    /** 用户昵称 */
    @Excel(name = "用户名称")
    private String name;

    /** 用户邮箱 */
    @Excel(name = "用户邮箱")
    private String email;

    /**
     * 生日
     */
    @Excel(name = "生日",dateFormat = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    private Date birthday;

    /** 手机号码 */
    @Excel(name = "手机号码")
    private String phonenumber;

    /**
     * 学历（字典）
     */
    @Excel(name = "学历",dictType = "edu_degree")
    @Dict(dictDataSource = "edu_degree")
    private String eduDegree;

    /**
     * 毕业院校
     */
    @Excel(name = "毕业院校")
    private String school;

    /**
     * 入职时间
     */
    @TableField("HIREDATE")
    @Excel(name = "入职时间",dateFormat = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    private Date hiredate;

    /**
     * 职位
     */
    @Excel(name = "职位",dictType = "office")
    @Dict(dictDataSource = "office")
    private String office;

    /**
     * 地址
     */
    @Excel(name = "地址")
    private String address;

    /**
     * 身份证号
     */
    @Excel(name = "身份证号")
    private String idCard;

    /**
     * 微信公众号用到
     */
    private String openId;

    /**
     * 钉钉系统中的用户id
     */
    private String dingUserId;

    /**
     * 是否统计考勤
     */
    private Integer isBoss;

    /**
     * 是否提醒
     */
    private Integer isRemind;

    /**
     * 剩余加班时长
     */
    @Excel(name = "剩余加班时长")
    private Double overworkHour;

    /** 用户性别 */
    @Excel(name = "用户性别", readConverterExp = "0=男,1=女,2=未知")
    private String sex;

    /** 用户头像 */
    private String avatar;

    /** 密码 */
    private String password;

    /**
     * md5密码盐
     */
    @TableField("SALT")
    private String salt;

    /** 帐号状态（0正常 1停用） */
    @Excel(name = "帐号状态", readConverterExp = "0=正常,1=停用")
    private String status;

    @TableLogic
    /** 删除标志（0代表存在 2代表删除） */
    private String delFlag;

    /**
     * 是否可添加项目
     */
    private Integer isAddProject;

    /** 最后登录IP */
    @Excel(name = "最后登录IP", type = Type.EXPORT)
    private String loginIp;

    /** 最后登录时间 */
    @Excel(name = "最后登录时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss", type = Type.EXPORT)
    private Date loginDate;

    /** 部门对象 */
    @Excels({
        @Excel(name = "部门名称", targetAttr = "deptName", type = Type.EXPORT),
        @Excel(name = "部门负责人", targetAttr = "leader", type = Type.EXPORT)
    })
    @TableField(exist = false)
    private SysDept dept;

    @TableField(exist = false)
    /** 角色对象 */
    private List<SysRole> roles;

    @TableField(exist = false)
    /** 角色组 */
    private Long[] roleIds;

    @TableField(exist = false)
    /** 岗位组 */
    private Long[] postIds;

    @TableField(exist = false)
    /** 角色ID */
    private Long roleId;

    public boolean isAdmin()
    {
        return isAdmin(this.userId);
    }

    public static boolean isAdmin(Long userId)
    {
        return userId != null && 1L == userId;
    }

    public SysUser(Long userId)
    {
        this.userId = userId;
    }
}
